package trans.action;

import java.util.List;

import trans.model.Gatway;
import trans.service.GatwayDAO;
import trans.support.BasicSupport;

import com.opensymphony.xwork2.Preparable;

public class GatwayMgrAction extends BasicSupport implements Preparable{

	private static final long serialVersionUID = 1L;
	
	List<Gatway> gatwayList;
	
	Gatway gatway;
	
	@Override
	public void prepare() throws Exception {
		initManuShow();
		
	}

	public String index() throws Exception{
		gatwayList = GatwayDAO.getAllGatway();
		
		return "gatwayMgr";
	}
	
	public String addGatway() throws Exception{
		boolean result = GatwayDAO.saveGatway(gatway);
		if(!result){
			addActionError(getText("message.gatway.save.error.exist"));
		}else{
			addActionMessage(getText("message.gatway.create.success"));
		}
		gatwayList = GatwayDAO.getAllGatway();
		return "gatwayMgr";
	}
	
	Integer updateGatwayId;
	Integer updateGatwayStatus;
	public String updateGatwayStatus() throws Exception{
		GatwayDAO.updateGatwayStatus(updateGatwayId, updateGatwayStatus);
		
		gatwayList = GatwayDAO.getAllGatway();
		
		addActionMessage(getText("message.gatway.update.success"));
		return "gatwayMgr";
	}

	public List<Gatway> getGatwayList() {
		return gatwayList;
	}

	public void setGatwayList(List<Gatway> gatwayList) {
		this.gatwayList = gatwayList;
	}

	public Gatway getGatway() {
		return gatway;
	}

	public void setGatway(Gatway gatway) {
		this.gatway = gatway;
	}

	public Integer getUpdateGatwayId() {
		return updateGatwayId;
	}

	public void setUpdateGatwayId(Integer updateGatwayId) {
		this.updateGatwayId = updateGatwayId;
	}

	public Integer getUpdateGatwayStatus() {
		return updateGatwayStatus;
	}

	public void setUpdateGatwayStatus(Integer updateGatwayStatus) {
		this.updateGatwayStatus = updateGatwayStatus;
	}
	
}
